//|||||||||||||||||||||||||||||||||||||||||||||||

#include <sstream>
#include "GameEntity.hpp"

//|||||||||||||||||||||||||||||||||||||||||||||||

using namespace Ogre;

//|||||||||||||||||||||||||||||||||||||||||||||||

GameEntity GameEntity::Block;
GameEntity GameEntity::Apple;
GameEntity GameEntity::Bottle;
GameEntity GameEntity::ChocBar;
GameEntity GameEntity::MBPack;
GameEntity GameEntity::Pill;
GameEntity GameEntity::Pillow;
GameEntity GameEntity::WineGlass;
GameEntity GameEntity::Zippo;

bool GameEntity::entitiesInitialized = false;

//|||||||||||||||||||||||||||||||||||||||||||||||

void GameEntity::InitializeEntites(Ogre::SceneManager* pSceneMgr)
{
	Block.nbEntities = 0;
	Block.m_pEntity = pSceneMgr->createEntity("block", "Block.mesh");
	Block.baseName = "block";

	Apple.nbEntities = 0;
	Apple.m_pEntity = pSceneMgr->createEntity("apple", "AppleMesh.mesh");
	Apple.baseName = "apple";

	Bottle.nbEntities = 0;
	Bottle.m_pEntity = pSceneMgr->createEntity("bottle", "Bottle.mesh");
	Bottle.baseName = "bottle";

	ChocBar.nbEntities = 0;
	ChocBar.m_pEntity = pSceneMgr->createEntity("`chocBar", "ChocBar.mesh");
	ChocBar.baseName = "chocBar";

	MBPack.nbEntities = 0;
	MBPack.m_pEntity = pSceneMgr->createEntity("mbPack", "MBPack.mesh");
	MBPack.baseName = "mbPack";

	Pill.nbEntities = 0;
	Pill.m_pEntity = pSceneMgr->createEntity("pill", "Pill.mesh");
	Pill.baseName = "pill";

	Pillow.nbEntities = 0;
	Pillow.m_pEntity = pSceneMgr->createEntity("pillow", "Pillow.mesh");
	Pillow.baseName = "pillow";

	WineGlass.nbEntities = 0;
	WineGlass.m_pEntity = pSceneMgr->createEntity("wineGlass", "WineGlass.mesh");
	WineGlass.baseName = "wineGlass";

	Zippo.nbEntities = 0;
	Zippo.m_pEntity = pSceneMgr->createEntity("zippo", "Zippo.mesh");
	Zippo.baseName = "zippo";

	entitiesInitialized = true;
}

//|||||||||||||||||||||||||||||||||||||||||||||||

GameEntity::GameEntity()
{
	nbEntities = 0;
}

//|||||||||||||||||||||||||||||||||||||||||||||||

void GameEntity::setEntity(Ogre::Entity* entity)
{
	this->m_pEntity = entity;
}

//|||||||||||||||||||||||||||||||||||||||||||||||

Ogre::Entity* GameEntity::getNewEntity()
{
	if(nbEntities == 0)
	{
		nbEntities++;
		return m_pEntity;
	}
	else
	{
		std::ostringstream name;
		nbEntities++;
		name << baseName << nbEntities << std::ends;
		return m_pEntity->clone(name.str());
	}
	
}

//|||||||||||||||||||||||||||||||||||||||||||||||

Ogre::Entity* GameEntity::getNewEntity(const std::string & name)
{
	return m_pEntity->clone(name);
}